package me.hushuang.webb.back.mapper;

import me.hushuang.webb.back.model.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 *
 */
public interface UserMapper {

    @Insert("insert into sys_user(username, password, salt, role_ids, locked) values(#{username},#{password},#{salt},1, 1)")
    int createUser(User user);

    @Update("update sys_user set organization_id = #{organizationId}, username = #{username}, password=#{password}, salt=#{salt}, role_ids=#{roleIdsStr}, locked=#{locked}  where id = #{id}")
    void updateUser(User user);

    @Delete("delete from sys_user where id= #{id}")
    void deleteUser(@Param("id") Long userId);

    @Select("select id, organization_id, username, password, salt, role_ids as roleIdsStr, locked from sys_user where id=#{id}")
    User findOne(@Param("id") Long userId);

    @Select("select id, organization_id, username, password, salt, role_ids as roleIdsStr, locked from sys_user")
    List<User> findAll();

    @Select("select id, organization_id, username, password, salt, role_ids as roleIdsStr, locked from sys_user where username = #{username}")
    User findByUsername(@Param("username") String username);
}
